home *** CD-ROM | disk | FTP | other *** search
- #include <sys/types.h>
- #include <sys/param.h>
- #include <sys/socket.h>
- #include <sys/stropts.h>
- #include <sys/termios.h>
- #include <sys/ttold.h>
- #include <sys/sockio.h>
- #include <sys/file.h>
- #include <sys/if_ax.h>
- #include <netinet/in.h>
- #include <net/if.h>
- #include <netinet/if_ether.h>
- #include <stdio.h>
-
- u_char ax25broadcastaddr[7] = {
- 'Q'<<1, 'S'<<1, 'T'<<1, ' '<<1, ' '<<1, ' '<<1, '0'<<1
- };
- static struct ether_addr etherbroadcastaddr = {
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- };
-
- int
- main(argc, argv)
- char **argv;
- {
- struct termios tios;
- u_char ax25[7];
- struct ether_addr eth;
- char cmd[128], name[64];
- u_char *cp, c;
- int verbose = 0;
- int unit = 777;
- int fd, i;
-
- if(argc<4) {
- printf("usage: %s [-v] inet-addr ham-call-sign tty\n", *argv);
- exit(0);
- }
-
- if( !strcmp(argv[1], "-v") ) {
- verbose = 1;
- argv++;
- }
-
- fd = open(argv[3], O_RDWR);
- if(fd == -1) {
- perror("open");
- exit(1);
- }
-
- while(1) {
- if(verbose)
- if(ioctl(fd, I_LOOK, name) != -1)
- printf("popping module: %s\n", name);
- if(ioctl(fd, I_POP, 0) == -1)
- break;
- }
-
- if( ioctl(fd, TCGETS, &tios) <0) {
- perror("ioctl TCGETS");
- exit(1);
- }
-
- tios.c_cflag = CRTSCTS | B9600;
- tios.c_cflag |= CS8|CREAD|HUPCL;
- tios.c_iflag = IGNBRK;
- if( ioctl(fd, TCSETS, &tios) <0) {
- perror("ioctl TCSETS");
- exit(1);
- }
-
- if(verbose)
- printf("pushing module: ax25\n");
- if( ioctl(fd, I_PUSH, "ax25") == -1) {
- perror("ioctl I_PUSH");
- exit(1);
- }
-
- if( ioctl(fd, AXIOGUNIT, &unit) != -1) {
- if(verbose)
- printf("network device: ax%d\n", unit);
- } else {
- perror("ioctl AXIOGUNIT");
- exit(1);
- }
-
- /*
- * convert the HAM call sign to an ax25_addr
- */
- i = 0;
- bzero((caddr_t)ax25, sizeof(ax25));
- for(cp=(u_char *)argv[2]; *cp && (i<6); cp++) {
- if(*cp=='-') {
- cp++;
- break;
- }
- c = islower(*cp) ? toupper(*cp) : *cp;
- ax25[i++] = (u_char)(c << 1);
- }
- while(i<6)
- ax25[i++] = (u_char)(' ' << 1);
- while(*cp=='-')
- cp++;
- if(*cp)
- ax25[6] = (u_char)(*cp << 1);
-
- ax_ax2ether(ax25, ð);
- if( ioctl(fd, AXIOSHADDR, ð) == -1) {
- perror("ioctl AXIOSHADDR");
- exit(1);
- }
-
- sprintf(cmd, "ifconfig ax%d %s netmask + broadcast + up",
- unit, argv[1]);
- if(verbose)
- printf("execute: %s\n", cmd);
- system(cmd);
-
- while(sigpause(0)!=-1)
- ;
- return 0;
- }
-
-
- /*
- * convert an ax25 address to an ether_addr
- */
- ax_ax2ether(axhp, ethp)
- u_char *axhp;
- struct ether_addr *ethp;
- {
- u_char c;
- int i;
-
- printf("addresses: ax25 ");
- for(i=0; i<6; i++)
- printf("%02x.", axhp[i]);
- printf("%02x '", axhp[6]);
-
- for(i=0; i<(7-1); i++)
- printf("%c", axhp[i]>>1);
- printf("-%c' = ether ", axhp[6]>>1);
-
- if( !bcmp((caddr_t)axhp, (caddr_t)ax25broadcastaddr,
- sizeof(ax25broadcastaddr)) ) {
- bcopy((caddr_t)ðerbroadcastaddr, (caddr_t)ethp,
- sizeof(struct ether_addr));
- goto done;
- }
-
- ethp->ether_addr_octet[0] = 0x99;
- c = ((((axhp[0]>>1) - ' ') << 2) & 0xfc);
- c |= ((((axhp[1]>>1) - ' ') >> 4) & 0x03);
- ethp->ether_addr_octet[1] = c;
- c = ((((axhp[1]>>1) - ' ') << 4) & 0xf0);
- c |= ((((axhp[2]>>1) - ' ') >> 2) & 0x0f);
- ethp->ether_addr_octet[2] = c;
- c = ((((axhp[2]>>1) - ' ') << 6) & 0xc0);
- c |= ((((axhp[3]>>1) - ' ') ) & 0x3f);
- ethp->ether_addr_octet[3] = c;
- c = ((((axhp[4]>>1) - ' ') << 2) & 0xfc);
- c |= ((((axhp[5]>>1) - ' ') >> 4) & 0x03);
- ethp->ether_addr_octet[4] = c;
- c = ((((axhp[5]>>1) - ' ') << 4) & 0xf0);
- c |= ((((axhp[6]>>1) - '0') ) & 0x0f);
- ethp->ether_addr_octet[5] = c;
-
- done:
- for(i=0; i<sizeof(struct ether_addr)-1; i++)
- printf("%02x:", ethp->ether_addr_octet[i]);
- printf("%02x\n", ethp->ether_addr_octet[5]);
- return 0;
- }
-
-